package com.siyu.basedata.xajresult.controller;

import com.siyu.basedata.xajresult.domain.XajResult;
import com.siyu.basedata.xajresult.service.IXajResultService;
import com.siyu.common.core.controller.BaseController;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.common.core.page.TableDataInfo;
import com.siyu.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 新安江模型计算结果Controller
 *
 * @author hrhy
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/predict/xajresult")
public class XajResultController extends BaseController {
    @Autowired
    private IXajResultService xajResultService;

    /**
     * 查询新安江模型计算结果列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XajResult xajResult) {
        startPage();
        List<XajResult> list = xajResultService.selectXajResultList(xajResult);
        return getDataTable(list);
    }

    /**
     * 导出新安江模型计算结果列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, XajResult xajResult) {
        List<XajResult> list = xajResultService.selectXajResultList(xajResult);
        ExcelUtil<XajResult> util = new ExcelUtil<XajResult>(XajResult.class);
        util.exportExcel(response, list, "新安江模型计算结果数据");
    }

    /**
     * 获取新安江模型计算结果详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(xajResultService.selectXajResultById(id));
    }

    /**
     * 新增新安江模型计算结果
     */
    @PostMapping
    public AjaxResult add(@RequestBody XajResult xajResult) {
        return toAjax(xajResultService.insertXajResult(xajResult));
    }

    /**
     * 修改新安江模型计算结果
     */
    @PutMapping
    public AjaxResult edit(@RequestBody XajResult xajResult) {
        return toAjax(xajResultService.updateXajResult(xajResult));
    }

    /**
     * 删除新安江模型计算结果
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(xajResultService.deleteXajResultByIds(ids));
    }
}
